package com.dnzx.socket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConnectionThread implements Runnable {

    private static final Logger LOGGER = LoggerFactory.getLogger(ConnectionThread.class);

    private Socket socket;
    //private final SocketServer socketServer;
    //private SocketListenerPusher socketListenerPusher;
    //private boolean connected = false;
    private boolean getEpc = false;
    private static final byte[] GET_EPC = new byte[]{(byte) 0xBB, 0x19, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x06, 0x2E, 0x0D, 0x0A};

    public ConnectionThread(Socket socket) {
        this.socket = socket;
    }

    public ConnectionThread(Socket socket, boolean getEpc) {
        this.socket = socket;
        this.getEpc = getEpc;
    }

//    public ConnectionThread(Socket socket, SocketListenerPusher socketListenerPusher) {
//        this.socket = socket;
//        this.socketListenerPusher = socketListenerPusher;
//        connected = true;
//    }

    @Override
    public void run() {

        InputStream inputstream = null;
        OutputStream outputstream = null;
        try {
            System.out.println(getEpc);

            inputstream = socket.getInputStream();
            outputstream = socket.getOutputStream();


        } catch (Exception e) {
            LOGGER.error("socket handle:", e);
        } finally {
//            if (inputstream != null) {
//                try {
//                    inputstream.close();
//                } catch (Exception ex) {
//                    LOGGER.error("inputstream close:", ex);
//                }
//            }
//            if (outputstream != null) {
//                try {
//                    outputstream.close();yan
//                } catch (Exception ex) {
//                     LOGGER.error("outputstream close:", ex);
//                }
//            }
//            if (socket != null) {
//                try {
//                    socket.close();
//                    socket=null;
//                } catch (Exception ex) {
//                      LOGGER.error("socket close:", ex);
//                }
//            }
        }
    }
}
